import React, { Component } from 'react'

export default class Child extends Component {
  state = {
    text: '',
  }
  render() {
    return <div>Child-{this.state.text}</div>
  }

  //WARNING! To be deprecated in React v17. Use new lifecycle static getDerivedStateFromProps instead.
  componentWillReceiveProps(nextProps) {
    console.log('Child componentWillReceiveProps', nextProps, this.props)

    // 最新获取父组件传来的属性，可以利用属性进行ajax或者逻辑处理
    // 把属性转为自己的状态
    this.setState({
      text: nextProps.text + 'ww',
    })
  }
}
